home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / nindy-share / ttycntl.h < prev    next >
C/C++ Source or Header  |  1992-09-11  |  4KB  |  113 lines

  1. /******************************************************************************
  2.  * This include file provides BSD/USG-compatible tty control for a host utility
  3.  * that interacts with NINDY.  As of this writing, it is used by the gdb960
  4.  * remote communications module (remote.c) and the comm960 utility.
  5.  * 
  6.  * It is assumed that 'USG' is defined on the compiler invocation line if the
  7.  * code should compile and run on a USG/SysV system.  Otherwise, BSD is assumed.
  8.  *
  9.  * The application code has access to these macros:
  10.  *
  11.  *    TTY_STRUCT    Data type used by tty functions (ioctls and the
  12.  *            following macros).
  13.  *
  14.  *    TTY_NINDYTERM(tty)
  15.  *            'tty' is assumed to be a TTY_STRUCT describing the
  16.  *            terminal.  It is modified as appropriate to allow
  17.  *            all user input to be passed through unmodified to NINDY
  18.  *            as soon as it is typed, and to allow all NINDY output
  19.  *            to be passed through unmodified to the display as soon
  20.  *            as it is received.
  21.  *
  22.  *    TTY_REMOTE(tty,baud)
  23.  *            'tty' is assumed to be a TTY_STRUCT describing the
  24.  *            serial connection between the host and NINDY.  It is
  25.  *            initialized as appropriate to allow communications
  26.  *            between the host and NINDY at the specified baud rate
  27.  *            (which must be one of the "B..." defined constants).
  28.  *
  29.  *    TTY_FLUSH(fd)    flush all pending input and output on the tty whose
  30.  *            file descriptor is 'fd'.
  31.  *
  32.  *    TTY_NBREAD(fd,n,bufptr)
  33.  *            Performs non-blocking read of 'n' characters on the
  34.  *            file descriptor 'fd'.  Sets the integer 'n' to the
  35.  *            number of characters actually read.  The characters
  36.  *            are read into the buffer pointed at by bufptr.
  37.  *
  38.  * In addition, the BSD ioctl commands TIOCGETP and TIOCSETP are defined to
  39.  * have the same meanings under USG: retrieve and set (respectively) the
  40.  * parameters of a tty.
  41.  ******************************************************************************/
  42.  
  43. #ifdef USG
  44.  
  45. #    include <termio.h>
  46. #    define TTY_STRUCT    struct termio
  47. #    define TIOCGETP        TCGETA
  48. #    define TIOCSETP        TCSETAF
  49.  
  50.     /* NOTE!:
  51.      *    Remove CLOCAL from following macro if you will be accessing
  52.      *    the i960 system via a modem.
  53.      */
  54. #       define TTY_REMOTE(tty,baud) {                   \
  55.                 tty.c_iflag = IXON | IXOFF;             \
  56.                 tty.c_oflag = 0;                        \
  57.                 tty.c_cflag = baud|CS8|CREAD|CLOCAL;    \
  58.                 tty.c_lflag = 0;                        \
  59.                 tty.c_cc[VEOF] = 1;                     \
  60.                 tty.c_cc[VEOL] = 0;                     \
  61.         }
  62.  
  63. #    define TTY_NINDYTERM(tty) {        \
  64.         tty.c_iflag = 0;        \
  65.         tty.c_oflag = 0;        \
  66.         tty.c_lflag = ISIG;        \
  67.         tty.c_cc[VEOF] = 1;        \
  68.         tty.c_cc[VEOL] = 0;        \
  69.     }
  70.  
  71. #    define TTY_FLUSH(fd)    ioctl(fd,TCFLSH,2);
  72.  
  73. #       define TTY_NBREAD(fd,n,bufptr) {            \
  74.         int _saveflags_;                \
  75.         _saveflags_ = fcntl( fd, F_GETFL, 0 );        \
  76.         fcntl( fd, F_SETFL, _saveflags_ | O_NDELAY );    \
  77.         n = read( fd, bufptr, n );            \
  78.         fcntl( fd, F_SETFL, _saveflags_ );        \
  79.     }
  80.  
  81. #else    /* BSD */
  82.  
  83. #    include <sys/ioctl.h>
  84. #    define TTY_STRUCT    struct sgttyb
  85. #       define TTY_REMOTE(tty,baud){            \
  86.                 tty.sg_flags = RAW | TANDEM;    \
  87.                 tty.sg_ispeed = baud;           \
  88.                 tty.sg_ospeed = baud;           \
  89.         }
  90.  
  91. #    define TTY_NINDYTERM(tty)    {    \
  92.         tty.sg_flags |= CBREAK;        \
  93.         tty.sg_flags &= ~(ECHO|CRMOD);    \
  94.     }
  95.  
  96. #    define TTY_FLUSH(fd)    { int _i_ = 0; ioctl(fd,TIOCFLUSH,&_i_); }
  97.  
  98. #       define TTY_NBREAD(fd,n,bufptr) {        \
  99.         int _n_;                \
  100.         ioctl(fd,FIONREAD,&_n_);        \
  101.         n = (_n_>0) ? read(fd,bufptr,n) : 0;    \
  102.     }
  103. #endif
  104.  
  105.  
  106.  
  107. #ifndef B19200
  108. #    define B19200 EXTA
  109. #endif
  110. #ifndef B38400
  111. #    define B38400 EXTB
  112. #endif
  113.